#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;

LL h, w, rs, cs, n, q;
map<int, vector<int>> mpr, mpc;

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> h >> w >> rs >> cs >> n;

    for(int i = 0, r, c; i < n; i ++){
        cin >> r >> c;

        if(mpr.count(r)){
            vector<int> &t = mpr[r];
            t.push_back(c);
        }else{
            vector<int> t;
            t.push_back(c);
            mpr[r] = t;
        }

        if(mpc.count(c)){
            vector<int> &t = mpc[c];
            t.push_back(r);
        }else{
            vector<int> t;
            t.push_back(r);
            mpc[c] = t;
        }
    }

    for(auto &[key, val] : mpr){
        sort(val.begin(), val.end());
    }

    for(auto &[key, val] : mpc){
        sort(val.begin(), val.end());
    }

    cin >> q;
    string op;
    int li;
    while(q --){
        cin >> op >> li;

        if(op == "D"){
            LL nx = rs + li;

            if(mpc.count(cs)){
                vector<int> &t = mpc[cs];
                if(lower_bound(t.begin(), t.end(), rs) != t.end()){
                    int k = lower_bound(t.begin(), t.end(), rs) - t.begin();
                    nx = min(nx, (LL)t[k] - 1);
                }
            }

            nx = min(nx, (LL)h);

            rs = nx;
        }else if(op == "U"){
            LL nx = rs - li;

            if(mpc.count(cs)){
                vector<int> &t = mpc[cs];


                if(lower_bound(t.begin(), t.end(), rs) == t.end()){
                    nx = max(nx, (LL)t[t.size() - 1] + 1);
                }else if(lower_bound(t.begin(), t.end(), rs) != t.begin()){
                    int k = lower_bound(t.begin(), t.end(), rs) - t.begin();

 
 
                    k --;
                    nx = max(nx, (LL)t[k] + 1);
                }
            }

            nx = max((LL)1, nx);

            rs = nx;
        }else if(op == "R"){
            LL ny = cs + li;

            if(mpr.count(rs)){
                vector<int> &t = mpr[rs];

                if(lower_bound(t.begin(), t.end(), cs) != t.end()){
                    int k = lower_bound(t.begin(), t.end(), cs) - t.begin();
                    ny = min(ny, (LL)t[k] - 1);
                }
            }

            ny = min(ny, w);

            cs = ny;
        }else{ // op == "L"
            LL ny = cs - li;

            if(mpr.count(rs)){
                vector<int> &t = mpr[rs];

                if(lower_bound(t.begin(), t.end(), cs) == t.end()){
                    ny = max(ny, (LL)t[t.size() - 1] + 1 );
                }else if(lower_bound(t.begin(), t.end(), cs) != t.begin()){
                    int k = lower_bound(t.begin(), t.end(), cs) - t.begin();
                    k --;
                    ny = max(ny, (LL)t[k] + 1);
                }
            }

            ny = max((LL)1, ny);

            cs = ny;
        }


        cout << rs << " " << cs << '\n';
    }


    return 0;
}